package com.tudouji.framework.config;

import com.tudouji.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.password.PasswordEncoder;

public class Sha1 implements PasswordEncoder {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Override
    public String encode(CharSequence rawPassword) {
//        logger.info("加密前：" + rawPassword.toString());
        return EncrypAES.encrypt(rawPassword.toString());
//        return rawPassword.toString();
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
//        logger.info("编码2：" + rawPassword);
        return StringUtils.equalsIgnoreCase(EncrypAES.encrypt(rawPassword.toString()), encodedPassword);
//        return true;
    }

    public String decode(String encodedPassword){
//        logger.info("编码1：" + encodedPassword);
        return EncrypAES.decrypt(encodedPassword);
    }
}
